package com.upay.android.controller.activity;

import static com.upay.android.controller.helper.Keys.*;

import com.upay.android.controller.helper.Results;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

public class MainActivity extends Activity {
	
	/* ---- Constants ---- */

	/* ---- Business Methods ---- */
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        SharedPreferences sharedPreferences = getSharedPreferences(UPAY_PREFERENCES, 0);
        Intent intent = null;
        if (sharedPreferences.getString(USERID, null) == null) {
        	intent = new Intent(this, AuthenticationActivity.class);
        	startActivityForResult(intent, 1);
        } else {  
        	intent = new Intent(this, GroupAccountActivity.class);
        	startActivity(intent);
        	finish();
        }

        
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);
    	
    	Intent intent = null;
    	
    	switch (resultCode) {
    		case Results.AUTHENTICATED:
    			intent = new Intent(this, GroupAccountActivity.class);   	    	
    			startActivity(intent);
    			finish();
    	        break;
    		case Results.ACCOUNT_CREATED:
            	intent = new Intent(this, AuthenticationActivity.class);
            	startActivityForResult(intent, 1);
    			break;
    		default:
    			break;
    	}	
    }

}